#!/bin/sh

set -e

#DEBHELPER#


case "$1" in
    configure)
        # ensure /var/lib/snapd/lib/gl is cleared
        if dpkg --compare-versions "$2" lt-nl "2.0.7"; then
            ldconfig
        fi
        # start required services
        if [ -d /run/systemd/system ]; then
            systemctl daemon-reload
            # snapd.system-shutdown.service is not strictly needed on 14.04. Its functionality
            # is limited to core devices, we still include it here for the sake of comppleteness
            # in comparison to 16.04 setups.
            systemctl -f enable snapd.autoimport.service snapd.socket snapd.service snap.mount.service snapd.system-shutdown.service
            systemctl start snapd.autoimport.service snapd.socket snapd.service snap.mount.service
        fi

        # Ensure that the void directory has correct permissions.
        chmod 111 /var/lib/snapd/void

	case ":$PATH:" in
	    *:"/snap/bin":*)
		;;
	    *)
		echo "Please reboot, logout/login or source /etc/profile to have /snap/bin added to PATH."
		;;
	esac
esac
